package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.jl.jlapp.R;
import com.jl.jlapp.adapter.OrderDetailGoodsListAdapter;
import com.jl.jlapp.eneity.CancleOrderModel;
import com.jl.jlapp.eneity.CopyOrderShoppingCartModel;
import com.jl.jlapp.eneity.Order;
import com.jl.jlapp.eneity.OrderDetail;
import com.jl.jlapp.eneity.OrderDetail.ResultDataBean;
import com.jl.jlapp.eneity.OrderDetail.ResultDataBean.OfflinePaymentBean;
import com.jl.jlapp.eneity.OrderDetail.ResultDataBean.OrderDetailsBean;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;
import com.jl.jlapp.popu.ClearHistorySearhPopu;
import com.jl.jlapp.utils.CustomLanearLayoutManager;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class OrderDetailActivity
        extends AppCompatActivity
        implements OnClickListener {
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.after_sale_bottm)
    RelativeLayout after_sale_bottom;
    @BindView(R.id.after_sale_contact_customer_service)
    TextView after_sale_contact_customer_service;
    @BindView(R.id.after_sale_see)
    TextView after_sale_see;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.cancel_bottm)
    RelativeLayout cancel_bottom;
    @BindView(R.id.cancel_buy_again)
    TextView cancel_buy_again;
    @BindView(R.id.cancel_contact_customer_service)
    TextView cancel_contact_customer_service;
    @BindView(R.id.cancel_delete_order)
    TextView cancel_delete_order;
    private long chaoshitime;
    ClearHistorySearhPopu clearHistorySearhPopu;
    public OnClickListener confirmCancelOrder = new OnClickListener() {
        public void onClick(View paramAnonymousView) {
            OrderDetailActivity.this.cancelOrder(4, "订单取消成功");
            OrderDetailActivity.this.clearHistorySearhPopu.dismiss();
        }
    };
    public OnClickListener confirmDeleteOrder = new OnClickListener() {
        public void onClick(View paramAnonymousView) {
            OrderDetailActivity.this.cancelOrder(11, "订单删除成功");
            OrderDetailActivity.this.clearHistorySearhPopu.dismiss();
            Intent intent = new Intent(OrderDetailActivity.this, MyOrderListActivity.class);
            OrderDetailActivity.this.startActivity(intent);
        }
    };
    private long countdownTime;
    DecimalFormat df;
    @BindView(R.id.finish_bottm)
    RelativeLayout finish_bottom;
    @BindView(R.id.finish_buy_again)
    TextView finish_buy_again;
    @BindView(R.id.finish_contact_customer_service)
    TextView finish_contact_customer_service;
    @BindView(R.id.finish_delete_order)
    TextView finish_delete_order;
    @BindView(R.id.finish_evaluate_and_show)
    TextView finish_evaluate_and_show;
    OrderDetailGoodsListAdapter goodsListAdapter;
    Handler handler = new Handler();
    @BindView(R.id.icon_state)
    ImageView icon_state;
    @BindView(R.id.invoice)
    TextView invoice;
    @BindView(R.id.invoice_layout)
    LinearLayout invoice_layout;
    int isHasEvaluation;
    @BindView(R.id.my_order_combined_goods_num)
    TextView my_order_combined_goods_num;
    @BindView(R.id.my_order_combined_num)
    TextView my_order_combined_num;
    @BindView(R.id.my_order_freight)
    TextView my_order_freight;
    @BindView(R.id.name)
    TextView name;
    String nameStr = "";
    ArrayList<OrderDetailsBean> orderDetailsBeanList = new ArrayList();
    int orderId = -1;
    ArrayList<Order> orderList;
    String orderNo;
    String orderState = "";
    int orderStateInt;
    @BindView(R.id.order_commit_time)
    TextView order_commit_time;
    @BindView(R.id.order_no)
    TextView order_no;
    @BindView(R.id.order_state)
    TextView order_state;
    @BindView(R.id.order_tracing_detail)
    ImageView order_tracing_detail;
    @BindView(R.id.order_tracing_message)
    TextView order_tracing_message;
    @BindView(R.id.order_tracing_time)
    TextView order_tracing_time;
    @BindView(R.id.out_of_time_tips)
    TextView out_of_time_tips;
    @BindView(R.id.pay_mode_layout)
    LinearLayout pay_mode_layout;
    @BindView(R.id.pay_mode_view)
    TextView pay_mode_view;
    @BindView(R.id.pay_time_layout)
    LinearLayout pay_time_layout;
    @BindView(R.id.pay_time_view)
    TextView pay_time_view;
    @BindView(R.id.pay_type_layout)
    LinearLayout pay_type_layout;
    @BindView(R.id.pay_type_view)
    TextView pay_type_view;
    @BindView(R.id.phone)
    TextView phone;
    String phoneStr = "";
    int postage_pay_type = -1;
    private ProgressDialog progressDialog;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    Runnable runnable = new Runnable() {
        public void run() {
            if ((OrderDetailActivity.this.countdownTime <= 0L) && (OrderDetailActivity.this.wait_pay_bottom.getVisibility() == View.VISIBLE)) {
                OrderDetailActivity.this.orderState = "已取消";
                OrderDetailActivity.this.timer_view.setVisibility(View.GONE);
                OrderDetailActivity.this.out_of_time_tips.setVisibility(View.GONE);
                OrderDetailActivity.this.icon_state.setImageResource(R.drawable.icon_cancel_white);
                OrderDetailActivity.this.order_state.setText("已取消");
                OrderDetailActivity.this.wait_pay_bottom.setVisibility(View.GONE);
                OrderDetailActivity.this.cancel_bottom.setVisibility(View.VISIBLE);
                OrderDetailActivity.this.handler.removeCallbacks(OrderDetailActivity.this.runnable);
            }
            long l2 = OrderDetailActivity.this.countdownTime / 1000L;
            long l1 = l2 / 3600L;
            long l3 = l2 % 3600L;
            l2 = l3 / 60L;
            l3 %= 60L;
            String str1 = l1 + "";
            if (l1 < 10L) {
                str1 = "0" + l1;
            }
            String str2 = l2 + "";
            if (l2 < 10L) {
                str2 = "0" + l2;
            }
            String str3 = l3 + "";
            if (l3 < 10L) {
                str3 = "0" + l3;
            }
            OrderDetailActivity.this.timer_view.setText(str1 + ":" + str2 + ":" + str3);
            OrderDetailActivity.this.handler.postDelayed(this, 1000L);
        }
    };
    private String timefromServer;
    @BindView(R.id.timer)
    TextView timer_view;
    @BindView(R.id.top_apply)
    TextView top_apply;
    double totalPayMoney = 0.0D;
    int userId = -1;
    @BindView(R.id.wait_pay_bottm)
    RelativeLayout wait_pay_bottom;
    @BindView(R.id.wait_pay_cancel_order)
    TextView wait_pay_cancel_order;
    @BindView(R.id.wait_pay_contact_customer_service)
    TextView wait_pay_contact_customer_service;
    @BindView(R.id.wait_pay_pay_order)
    TextView wait_pay_pay_order;
    @BindView(R.id.wait_receive_bottm)
    RelativeLayout wait_receive_bottom;
    @BindView(R.id.wait_receive_contact_customer_service)
    TextView wait_receive_contact_customer_service;
    @BindView(R.id.wait_receive_tracing_order)
    TextView wait_receive_tracing_order;

    private void cancelOrder(int paramInt, String paramString) {
        Net.get().cancleOrder(this.orderId, this.userId, paramInt)
                .compose(Transformer.<CancleOrderModel>switchSchedulers())
                .subscribe(new CommonObserver<CancleOrderModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(CancleOrderModel cancleOrderModel) {

                    }
                });
    }

    private void getTimeDuring() {
        this.chaoshitime = 14400000L;
        if (this.postage_pay_type == 0) {
            this.chaoshitime = 14400000L;
        } else {
            Object localObject = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                localObject = ((SimpleDateFormat) localObject).parse(this.timefromServer);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            long l1 = new Date().getTime();
            long l2 = ((Date) localObject).getTime();
            this.countdownTime = (this.chaoshitime - (l1 - l2));
            this.handler.postDelayed(this.runnable, 1000L);
            if (this.postage_pay_type != 1) {
            }
            this.chaoshitime = 86400000L;

        }
    }

    private void init() {
        getNetData();
    }

    private void setClickEvent() {
        this.back.setOnClickListener(this);
        this.order_tracing_detail.setOnClickListener(this);
        this.wait_receive_tracing_order.setOnClickListener(this);
        this.top_apply.setOnClickListener(this);
        this.after_sale_see.setOnClickListener(this);
        this.wait_pay_cancel_order.setOnClickListener(this);
        this.finish_delete_order.setOnClickListener(this);
        this.cancel_delete_order.setOnClickListener(this);
        this.finish_buy_again.setOnClickListener(this);
        this.cancel_buy_again.setOnClickListener(this);
        this.wait_pay_pay_order.setOnClickListener(this);
        this.wait_pay_contact_customer_service.setOnClickListener(this);
        this.wait_receive_contact_customer_service.setOnClickListener(this);
        this.finish_contact_customer_service.setOnClickListener(this);
        this.cancel_contact_customer_service.setOnClickListener(this);
        this.after_sale_contact_customer_service.setOnClickListener(this);
        this.finish_evaluate_and_show.setOnClickListener(this);
    }

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(this);
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void buyAgainClick() {
        Net.get().buyAgain(this.orderId, this.userId)
                .compose(Transformer.<CopyOrderShoppingCartModel>switchSchedulers())
                .subscribe(new CommonObserver<CopyOrderShoppingCartModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(CopyOrderShoppingCartModel copyOrderShoppingCartModel) {

                    }
                });
    }

    public void cancelOrderClick() {
        this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, this.confirmCancelOrder, Integer.valueOf(2));
        this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.order_detail_page), 17, 0, 0);
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void deleteOrderClick() {
        this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, this.confirmDeleteOrder, Integer.valueOf(4));
        this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.order_detail_page), 17, 0, 0);
    }

    public void getNetData() {
        if ((this.orderId != -1) && (this.userId != -1)) {
            Net.get().getOrderDetail(this.orderId, this.userId)
                    .compose(Transformer.<OrderDetail>switchSchedulers())
                    .subscribe(new CommonObserver<OrderDetail>() {
                        @Override
                        protected void onError(String errorMsg) {

                        }

                        @Override
                        protected void onSuccess(OrderDetail orderDetail) {

                        }
                    });
        } else {
            if (this.userId == -1) {
                startActivity(new Intent(this, LoginActivity.class));
                return;
            }
            if (this.orderId != -1)
                Toast.makeText(this, "页面传值没有接收到", Toast.LENGTH_SHORT).show();
        }

    }

    protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent) {
        buildProgressDialog();
        getNetData();
    }

    public void onClick(View paramView) {
        Intent intent;
        switch (paramView.getId()) {
            case R.id.back:
                finish();
                return;
            case R.id.order_tracing_detail:
                viewTracingOrderClick();
                return;
            case R.id.top_apply:
                intent = new Intent(this, AfterSaleApplyActivity.class);
                intent.putExtra("orderId", this.orderId);
                intent.putExtra("name", this.nameStr);
                intent.putExtra("phone", this.phoneStr);
                startActivityForResult(intent, 0);
                return;
            case R.id.wait_pay_cancel_order:
                cancelOrderClick();
                return;
            case R.id.wait_pay_contact_customer_service:
                startActivity(new Intent(this, CustomerServiceActivity.class));
                return;
            case R.id.wait_pay_pay_order:
                payOrderClick();
                return;
            case R.id.wait_receive_contact_customer_service:
                startActivity(new Intent(this, CustomerServiceActivity.class));
                return;
            case R.id.wait_receive_tracing_order:
                viewTracingOrderClick();
                return;
            case R.id.finish_delete_order:
                deleteOrderClick();
                return;
            case R.id.finish_contact_customer_service:
                startActivity(new Intent(this, CustomerServiceActivity.class));
                return;
            case R.id.finish_evaluate_and_show:
                if (this.isHasEvaluation == 0) {
                    intent = new Intent(this, ShouldEvaluationActivity.class);
                    intent.putExtra("orderId", this.orderId);
                    startActivity(intent);
                    return;
                }
                intent = new Intent(this, EvaluationDetailActivity.class);
                intent.putExtra("orderId", this.orderId);
                startActivity(intent);
                return;
            case R.id.finish_buy_again:
                buyAgainClick();
                return;
            case R.id.cancel_delete_order:
                deleteOrderClick();
                return;
            case R.id.cancel_contact_customer_service:
                startActivity(new Intent(this, CustomerServiceActivity.class));
                return;
            case R.id.cancel_buy_again:
                buyAgainClick();
                return;
            case R.id.after_sale_contact_customer_service:
                startActivity(new Intent(this, CustomerServiceActivity.class));
                return;
        }
        intent = new Intent(this, AfterSaleDetailActivity.class);
        intent.putExtra("orderId", this.orderId);
        startActivity(intent);
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.order_detail_activity);
        this.orderId = getIntent().getIntExtra("orderId", -1);
        ButterKnife.bind(this);
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", -1);
        buildProgressDialog();
        this.df = new DecimalFormat(".00");
        init();
    }

    protected void onDestroy() {
        super.onDestroy();
        this.handler.removeCallbacks(this.runnable);
    }

    public void payOrderClick() {
        Intent localIntent = null;
        if ((this.totalPayMoney >= 0.0D) && (this.totalPayMoney < 50000.0D)) {
            localIntent = new Intent(this, PayOrderActivity.class);
        } else {
            if (localIntent != null) {
                localIntent.putExtra("payMoney", this.totalPayMoney);
                localIntent.putExtra("orderId", this.orderId);
                localIntent.putExtra("orderNo", this.orderNo);
                localIntent.putExtra("postagePayType", this.postage_pay_type);
                localIntent.putExtra("fromDetailPage", 1);
                startActivity(localIntent);
            }
            if (this.totalPayMoney >= 50000.0D) {
                localIntent = new Intent(this, UnderlineActivity.class);
            } else {
                Toast.makeText(this, "订单异常", Toast.LENGTH_SHORT).show();
            }
        }
    }

    public void setAdapter() {
        CustomLanearLayoutManager localCustomLanearLayoutManager = new CustomLanearLayoutManager(this);
        localCustomLanearLayoutManager.setScrollEnabled(false);
        this.recyclerView.setLayoutManager(localCustomLanearLayoutManager);
        this.goodsListAdapter = new OrderDetailGoodsListAdapter(R.layout.order_detail_goods_list_item, this.orderDetailsBeanList);
        this.recyclerView.setAdapter(this.goodsListAdapter);
    }

    public void viewTracingOrderClick() {
        Intent localIntent = new Intent(this, OrderTracingActivity.class);
        localIntent.putExtra("orderId", this.orderId);
        localIntent.putExtra("orderState", this.orderState);
        startActivity(localIntent);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/OrderDetailActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */